import java.util.Comparator;

/**
 * Author: Daniel Michalski
 * Date: 10.03.13
 */

public class TComp implements Comparator<String> {
    @Override
    public int compare(String o1, String o2) {
        int i, j, k;
        String aStr, bStr;

        aStr = o1;
        bStr = o2;

        i = aStr.lastIndexOf(' ');
        j = bStr.lastIndexOf(' ');

        k = aStr.substring(i).compareTo(bStr.substring(j));
        if (k == 0)
            return aStr.compareTo(bStr);
        else
            return k;
    }
}
